package com.core.dao.mybatismysql;


import com.core.bean.Product;
import com.core.dao.IProductDao;
import com.core.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class ProductDao implements IProductDao {

    @Override
    public int add(Product entity) throws Exception {
        SqlSession session = MybatisUtils.getSession();
        IProductDao iProductDao = session.getMapper(IProductDao.class);
        return iProductDao.add(entity);
    }

    @Override
    public int remove(String id) throws Exception {
        SqlSession session = MybatisUtils.getSession();
        IProductDao iProductDao = session.getMapper(IProductDao.class);
        return iProductDao.remove(id);
    }

    @Override
    public int modify(Product entity) throws Exception {
        SqlSession session = MybatisUtils.getSession();
        IProductDao iProductDao = session.getMapper(IProductDao.class);
        return iProductDao.modify(entity);
    }

    @Override
    public Product findEntityById(String id) throws Exception {
        SqlSession session = MybatisUtils.getSession();
        IProductDao iProductDao = session.getMapper(IProductDao.class);
        return iProductDao.findEntityById(id);
    }

    @Override
    public List<Product> findByCid(String cid) {
        SqlSession session = MybatisUtils.getSession();
        IProductDao iProductDao = session.getMapper(IProductDao.class);
        return iProductDao.findByCid(cid);
    }
}
